// 1. 正常案例
// 2. 边界案例
// 3. 异常案例
// 4. 函数接口需要变更
// 5. int max(int *array, int len, int * result);
// 6. bool max(int *array, int len, int * result);


#include <stdio.h>
#include <assert.h>

bool max(int * array, int len, int * result){
  if(array != NULL && len > 0 && result != NULL){
    *result = array[0];
    for(int i = 1; i < len; ++i){
      if(*result < array[i]) {
        *result = array[i];
      }
    }
    return true;
  }
  return false;
}












int main(){
  //正常案例
  { 
    int result = 0;
    int array[] = {-1, 2, 3, 4};
    bool ok = max(array, sizeof(array)/sizeof(int), &result);
    assert(result == 4);
    assert(ok);
  }
  
  {
    int result = 0;
    int array[] = {-1, 3, 20};
    int ok = max(array, sizeof(array)/sizeof(int), &result);
    assert(result == 20 && ok);
  }
  {
    int result = 0;
    int array[] = {4, 3, 2, -1};
    int ok = max(array, sizeof(array)/sizeof(int), &result);
    assert(result == 4 && ok);
  }

  {
    int result = 0;
    int array[] = {1, 1, 1, 1};
    int ok = max(array, sizeof(array)/sizeof(int), &result);
    assert(result == 1 && ok);
  }

  {
    int result = 0;
    int array[] = {3, 4, 2, -1};
    int ok = max(array, sizeof(array)/sizeof(int), &result);
    assert(result == 4 && ok);
  }


  //边界案例

  {
    int result = 0;
    int array[] = {3,};
    int ok = max(array, sizeof(array)/sizeof(int), &result);
    assert(result == 3 && ok);
  }

  {
    int result = 0;
    int array[] = {-1,};
    int ok = max(array, sizeof(array)/sizeof(int), &result);
    assert(result == -1 && ok);
  }


  //异常案例
  {
    int result = 0;
    int ok = max(NULL, 0, &result); 
    assert(!ok);
  }

  {
    int result = 0;
    int array[] = {-1,};
    int ok = max(array, -1, &result);
    assert(!ok);
  }
  {
    int array[] = {-1,};
    int ok = max(array, 1, NULL);
    assert(!ok);
  }


  {
    int ok = max(NULL, -1, NULL);
    assert(!ok);
  }

  return 0;
}
